package cn.edu.ujn.booksshop.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.edu.ujn.booksshop.dao.Author;
import cn.edu.ujn.booksshop.dao.Stock;
import cn.edu.ujn.booksshop.dao.StockMapper;
import cn.edu.ujn.util.Page;
@Service
@Transactional
public class StockServiceImpl implements IStockService {

	@Autowired
	private StockMapper stockDao;
	@Override
	public int deleteByPrimaryKey(Integer stockid) {
		// TODO Auto-generated method stub
		return this.stockDao.deleteByPrimaryKey(stockid);
	}

	@Override
	public int insert(Stock row) {
		// TODO Auto-generated method stub
		return this.stockDao.insert(row);
	}

	@Override
	public int insertSelective(Stock row) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public Stock selectByPrimaryKey(Integer stockid) {
		// TODO Auto-generated method stub
		return this.stockDao.selectByPrimaryKey(stockid);
	}

	@Override
	public int updateByPrimaryKeySelective(Stock row) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int updateByPrimaryKey(Stock row) {
		// TODO Auto-generated method stub
		return this.stockDao.updateByPrimaryKey(row);
	}

	@Override
	public Page<Stock> selectAll(Integer page, Integer rows) {
		List<Stock> selectAll = this.stockDao.selectAll((page-1)*rows,rows);
		Integer total = this.selectStockListCount();
		Page<Stock> pages = new Page<Stock>();
		pages.setPage(page);
		pages.setRows(selectAll);
		pages.setSize(rows);
		pages.setTotal(total);
		
		return pages;
	}

	@Override
	public Integer selectStockListCount() {
		// TODO Auto-generated method stub
		return this.stockDao.selectStockListCount();
	}

}
